package imooc_math.graph;

import java.util.Vector;

import org.junit.Test;

//稠密图-邻接矩阵
public class DenseGraph implements Graph{
	//点 边 
	public int n;//节点数
	public int m;//边数
	public boolean directed;
	public boolean[][] g;
	public DenseGraph(int n,boolean directed){
		this.n = n;
		this.m = 0;
		this.directed = directed;
		g = new boolean[n][n];//默认为false
	}
	public int V(){return n;}
	public int E(){return m;}
	public void addEdge(int v,int w){
		if(hasEdge(v,w)){
			return;
		}
		g[v][w] = true;
		if(!directed){
			g[w][v] = true;
		}
		m++;
	}
	public boolean hasEdge(int v,int w){
		return g[v][w];
	}
	public Iterable adj(int v){
		Vector adjV = new Vector(n); 
		for(int i=0;i<n;i++){
			if(g[v][i]){
				adjV.add(i);
			}
		}
		return adjV;
	}	
	public void show() {		
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				System.out.print(g[i][j]+"\t");
			}
			System.out.println();
		}
		
	}
}
